#include "StdAfx.h"
#include "Image.h"
#include "BMPHeader.h"
#include "Canvas.h"

void CImage::SaveImage(const std::string& filename, CCanvas& canvas)
{
	FILE* output = fopen(filename.c_str(),"wb");
	
	int width = canvas.GetScreenWidth();
	int height = canvas.GetScreenHeight();

	fwrite(&BMPHeader(width, height), sizeof(BMPHeader), 1, output); 
	
	unsigned char* data = canvas.GetImageData();
	
	fwrite(data,width*height*3*sizeof(unsigned char),1,output);	
	delete[] data;
}